<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>产品档案登记页面</title>
    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link href="../../../../static/css/jquery.dataTables.min.css" rel="stylesheet">
    <link href="../../../../static/css/style.css" rel="stylesheet">
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../css/productionPlanRegistrationCss.css">
    <script>



        $(function () {


            //页面初始化给登记人赋值
            $.ajax({
                type:'POST',
                url: '/userShow.action',
                success:function (user){
                    $('#register').val(user.loginId);
                }
            })

            //页面初始化给创建时间赋值
            var date = new Date();
            $('#registerTime').text(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());

            //I,II,III级编号联动
            var iNum1;
            var iNum2;
            var aProvince = ["电子", "机械", "商品"];
            var aCity =[["计算机", "手机", "平板", "手表"],
                ["焊接器", "液压器"],
                ["学习用品", "生活用品"]];
            var aCountry =[[
                ["cpu", "gpu","内存条","固态硬盘","网卡"],
                ["处理器","显示器"],
                ["触摸屏","接口"],
                ["表芯","表带"],
            ],
                [
                    ["燃烧带", "焊锡", "焊接头"],
                    ["起重器", "铁块"]
                ],
                [
                    ["钢笔"],
                    ["枕头", "被子", "毛巾", "牙膏"]
                ]];

            $(function () {
                for(var i=0;i<aProvince.length;i++){
                    $('#firstKindName').append('<option>'+aProvince[i]+'</option>');
                };
                $('#firstKindName').change(function () {
                    $('#secondKindName').children().not(':eq(0)').remove();
                    $('#thirdKindName').children().not(':eq(0)').remove();
                    iNum1 = $(this).children('option:selected').index();
                    var aaCity = aCity[iNum1-1];
                    for(var j=0;j<aaCity.length;j++){
                        $('#secondKindName').append('<option>'+aaCity[j]+'</option>');
                    }
                });
                $('#secondKindName').change(function () {
                    $('#thirdKindName').children().not(':eq(0)').remove();
                    iNum2 = $(this).children('option:selected').index();
                    var aaCountry = aCountry[iNum1-1][iNum2-1];
                    for(var k=0;k<aaCountry.length;k++){
                        $('#thirdKindName').append('<option>'+aaCountry[k]+'</option>');
                    }
                })
            });


            //商品名称input鼠标离开校验是否已存在
            $('#productName').mouseleave(function () {

                var productName=$('#productName').val();


                //判断产品名称是否存在
                $.ajax({
                    type:'post',
                    url: '/JudgmentProductName.action',
                    data:'productName='+productName,
                    success:function(DFile) {
                        if(DFile==null || DFile==''){
                            $('#title_exist').hide();
                        }else {

                            $('#title_exist').show();
                        }
                    },
                });

            });

            //点击保存按钮判断产品I级分类、II级分类、III级分类、市场单价、计划成本单价是否为空
            $('#saveProductBtn').click(function () {



                var firstKindName=$('#firstKindName').val();
                var secondKindName=$('#secondKindName').val();
                var thirdKindName=$('#thirdKindName').val();
                var listPrice=$('#listPrice').val();
                var costPrice=$('#costPrice').val();

                if(firstKindName=='' || secondKindName=='' || thirdKindName=='' || listPrice=='' || costPrice==''){
                    $('#myModal').modal('show');
                }else {

                    if ($('#title_exist').is(':hidden')) {

                        var ProductObj={
                            productName:$('#productName').val(),
                            factoryName:$('#factoryName').val(),
                            firstKindName:$('#firstKindName').val(),
                            secondKindName:$('#secondKindName').val(),
                            thirdKindName:$('#thirdKindName').val(),
                            productNick:$('#productNick').val(),
                            type:$('#type').val(),
                            productClass:$('#productClass').val(),
                            personalUnit:$('#personalUnit').val(),
                            personalValue:$('#personalValue').val(),
                            listPrice:$('#listPrice').val(),
                            costPrice:$('#costPrice').val(),
                            warranty:$('#warranty').val(),
                            twinName:$('#twinName').val(),
                            twinId:$('#twinId').val(),
                            lifecycle:$('#lifecycle').val(),
                            amountUnit:$('#amountUnit').val(),
                            responsiblePerson:$('#responsiblePerson').val(),
                            providerGroup:$('#providerGroup').val(),
                            productDescribe:$('#productDescribe').val(),
                            register:$('#register').val(),
                            registerTime:$('#registerTime').text()
                        };
                        var jsonProduct = JSON.stringify(ProductObj);

                        //执行异步添加产品档案登记方法
                        $.ajax({
                            type:'post',
                            url:'/AddProduct.action',
                            contentType:'application/json;charset=utf-8',
                            data:jsonProduct,
                            success:function () {
                                alert("产品档案登记成功");
                                $('#productName').val('');
                                $('#factoryName').val('');
                                $('#firstKindName').val('');
                                $('#secondKindName').val('');
                                $('#thirdKindName').val('');
                                $('#productNick').val('');
                                $('#productClass').val('');
                                $('#personalUnit').val('');
                                $('#personalValue').val('');
                                $('#listPrice').val('');
                                $('#costPrice').val('');
                                $('#warranty').val('');
                                $('#twinName').val('');
                                $('#twinId').val('');
                                $('#lifecycle').val('');
                                $('#amountUnit').val('');
                                $('#responsiblePerson').val('');
                                $('#providerGroup').val('');
                                $('#productDescribe').val('');

                            }
                        });
                    } else {
                        alert("产品名称已存在,请重新修改产品名称");

                    }

                }


            });



            //点击清除按钮后清除所有的值
            $('#cleanAllBtn').click(function () {
                $('#productName').val('');
                $('#factoryName').val('');
                $('#firstKindName').val('');
                $('#secondKindName').val('');
                $('#thirdKindName').val('');
                $('#productNick').val('');
                $('#productClass').val('');
                $('#personalUnit').val('');
                $('#personalValue').val('');
                $('#listPrice').val('');
                $('#costPrice').val('');
                $('#warranty').val('');
                $('#twinName').val('');
                $('#twinId').val('');
                $('#lifecycle').val('');
                $('#amountUnit').val('');
                $('#responsiblePerson').val('');
                $('#providerGroup').val('');
                $('#productDescribe').val('');

            });

        });


    </script>
</head>
<body>

<div class="d1">
    <div style="margin-top: 10px"><h2>产品档案登记</h2>

    </div>
    <div class="container-fluid row">
        <H3>主信息</H3>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text"><span style="color: red;height: 20px;width: 20px">*</span>产品名称:</span>
            </div>
            <input type="text" class="form-control" id="productName" placeholder="">
            <span id="title_exist" style="display: none;color: red">产品名称已存在</span>
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">制造商:</span>
            </div>
            <input type="text" class="form-control" id="factoryName">
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text"><span style="color: red;height: 20px;width: 20px">*</span>I级分类:</span>
            </div>
            <select id="firstKindName" class="default-select  form-control wide">
                <option value="">----请选择----</option>
            </select>
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text"><span style="color: red;height: 20px;width: 20px">*</span>II级分类:</span>
            </div>
            <select id="secondKindName" class="default-select  form-control wide">
                <option value="">----请选择----</option>
            </select>
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text"><span style="color: red;height: 20px;width: 20px">*</span>III级分类:</span>
            </div>
            <select id="thirdKindName" class="default-select  form-control wide">
                <option value="">----请选择----</option>
            </select>
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">产品简称:</span>
            </div>
            <input type="text" class="form-control" id="productNick">
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">用途类型:</span>
            </div>
            <select id="type" class="default-select  form-control wide">
                <option value="">----请选择----</option>
                <option value="Y001-1">商品</option>
                <option value="Y001-2">物料</option>
            </select>
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">档次级别:</span>
            </div>
            <select id="productClass" class="default-select  form-control wide">
                <option value="">----请选择----</option>
                <option value="D001-3">低档</option>
                <option value="D001-2">中档</option>
                <option value="D001-1">高档</option>
            </select>
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">计量单位:</span>
            </div>
            <input type="text" class="form-control" id="personalUnit">
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">计量值:</span>
            </div>
            <input type="text" class="form-control" id="personalValue">
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text"><span style="color: red;height: 20px;width: 20px">*</span>市场单价(元):</span>
            </div>
            <input type="text" class="form-control" id="listPrice">
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text"><span style="color: red;height: 20px;width: 20px">*</span>计划成本单价:</span>
            </div>
            <input type="text" class="form-control" id="costPrice">
        </div>
    </div>

    <div class="container-fluid row">
        <h3>辅助信息</h3>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">保修期:</span>
            </div>
            <input type="text" class="form-control" id="warranty">
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">替代品名称:</span>
            </div>
            <input type="text" class="form-control" id="twinName">
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">替代品编号:</span>
            </div>
            <input type="text" class="form-control" id="twinId">
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">生命周期(年)</span>
            </div>
            <input type="text" class="form-control" id="lifecycle">
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">单位:</span>
            </div>
            <input type="text" class="form-control" id="amountUnit">
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">产品经理:</span>
            </div>
            <input type="text" class="form-control" id="responsiblePerson">
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">供应商集合:</span>
            </div>
            <input type="text" class="form-control" id="providerGroup" style="width: 380px;height: 80px">
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">产品描述:</span>
            </div>
            <input type="text" class="form-control" id="productDescribe" style="width: 380px;height: 80px">
        </div>
    </div>

    <div class="container-fluid row">
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">登记人:</span>
            </div>
            <input type="text" class="form-control" id="register" readonly="readonly">
        </div>
        <div class="input-group mb-4 col">
            <div class="input-group-prepend">
                <span class="input-group-text">建档时间:</span>
            </div>
            <span id="registerTime" style="background-color: white;width: 200px;"readonly="readonly"></span>
        </div>
    </div>

</div>


<button class="btn btn-success" id="saveProductBtn">提交</button>
<button id="cleanAllBtn" class="btn btn-primary">清除</button>

<!-- 页面输入不完全警告模态框 -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title"><p style="color: red">警告</p></h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                <p style="color: #51bf2e">产品I级分类、II级分类、III级分类、市场单价、计划成本单价为必填项</p>
            </div>

        </div>
    </div>
</div>


</body>
</html>